// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   check_choose_bat_ok.java

package stock.pay;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class check_choose_bat_ok extends HttpServlet
{

	public check_choose_bat_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 stock_db = new nseer_db_backup1(dbApplication);
		try
		{
			if (stock_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				int p = 0;
				String stock_ID = request.getParameter("stock_ID");
				String product_ID = request.getParameter("product_ID");
				String pay_ID = request.getParameter("pay_ID");
				String serial_number_group[] = request.getParameterValues("serial_number");
				String paid_amount[] = request.getParameterValues("paid_amount");
				String serial_number = "";
				String amount_number = "";
				if (serial_number_group != null)
				{
					for (int i = 0; i < serial_number_group.length; i++)
					{
						String sql2 = (new StringBuilder("select * from stock_balance_details_details where product_ID='")).append(product_ID).append("' and stock_ID='").append(stock_ID).append("' and serial_number='").append(serial_number_group[i]).append("'").toString();
						ResultSet rs2 = stock_db.executeQuery(sql2);
						if (rs2.next() && !paid_amount[i].equals("") && Double.parseDouble(paid_amount[i]) > rs2.getDouble("amount"))
							p++;
					}

					if (p == 0)
					{
						double amount = 0.0D;
						for (int i = 0; i < serial_number_group.length; i++)
							if (!paid_amount[i].equals(""))
							{
								serial_number = (new StringBuilder(String.valueOf(serial_number))).append(serial_number_group[i]).append(", ").toString();
								amount_number = (new StringBuilder(String.valueOf(amount_number))).append(paid_amount[i]).append(", ").toString();
								amount += Double.parseDouble(paid_amount[i]);
							}

						String sql1 = (new StringBuilder("update stock_paying_gathering set serial_number='")).append(serial_number).append("',amount_number='").append(amount_number).append("',amount='").append(amount).append("' where pay_ID='").append(pay_ID).append("' and product_ID='").append(product_ID).append("' and stock_ID='").append(stock_ID).append("' and check_tag='0'").toString();
						stock_db.executeUpdate(sql1);
						response.sendRedirect((new StringBuilder("stock/pay/check.jsp?pay_ID=")).append(pay_ID).toString());
					} else
					{
						response.sendRedirect((new StringBuilder("stock/pay/check_choose_bat_ok_b.jsp?pay_ID=")).append(pay_ID).append("&&product_ID=").append(product_ID).append("&&stock_ID=").append(stock_ID).toString());
					}
				} else
				{
					response.sendRedirect((new StringBuilder("stock/pay/check_choose_bat_ok_c.jsp?pay_ID=")).append(pay_ID).append("&&product_ID=").append(product_ID).append("&&stock_ID=").append(stock_ID).toString());
				}
				stock_db.commit();
				stock_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
